const express = require('express');
const router = express.Router();
const runASR_RT = require('../functions/runASR_RT');
const getASRStat = require('../functions/getASRStat');

// 实时语音识别
router.post('/realtime', async (req, res) => {
  try {
    const result = await runASR_RT.main(req.body);
    res.json(result);
  } catch (error) {
    console.error('实时语音识别错误:', error);
    res.status(500).json({
      code: -1,
      message: '实时语音识别服务错误'
    });
  }
});

// 获取语音识别状态
router.get('/status/:sessionId', async (req, res) => {
  try {
    const result = await getASRStat.main({
      sessionId: req.params.sessionId
    });
    res.json(result);
  } catch (error) {
    console.error('获取语音识别状态错误:', error);
    res.status(500).json({
      code: -1,
      message: '获取语音识别状态错误'
    });
  }
});

module.exports = router;